package com.project.util.wx;

import com.alibaba.fastjson.JSONObject;
import com.framework.core.http.HttpRequest;
import com.framework.core.http.HttpResponse;
import com.framework.core.http.HttpUtil;

/**
 * @Description:
 * @Author: zhuchi
 * @CreateDate: 2020/12/8 16:58
 * @Version: 1.0
 */
public class WxAuthUtil {

    public static JSONObject getOpenIdByCode(String code){
        String url = "https://api.weixin.qq.com/sns/oauth2/access_token?appid="+WxPaySignUtil.APP_ID+"&secret="+WxPaySignUtil.APP_SECRET+"&code="+code+"&grant_type=authorization_code";

        HttpRequest get = HttpUtil.createGet(url);

        get.charset("UTF-8");
        HttpResponse execute = get.execute();
        String bodyData = execute.body();
        System.out.println(bodyData);

        JSONObject jsonObject = JSONObject.parseObject(bodyData);

        return jsonObject;
    }

    public static void main(String[] args) {
        getOpenIdByCode("093flnll2IH5864KrJll2wqnD11flnl9");
    }

}
